<!DOCTYPE html>
<html xmlns:th="https://www.thymeleaf.org/">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>backend</title>
    <link rel="stylesheet" type="text/css" href="/bootstarp/css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="/css/index.css" />
    <link rel="stylesheet" type="text/css" href="/css/nmms.css" />
    <script src="/js/jquery.js" type="text/javascript" charset="utf-8"></script>
    <script src="/bootstarp/js/bootstrap.js" type="text/javascript" charset="utf-8"></script>
    <script src="/js/userSetting.js" type="text/javascript" charset="utf-8"></script>
    <script src="/js/bootstrap-paginator.js" type="text/javascript" charset="utf-8"></script>
    <script>
        $(function(){
            // 分页
            let options = {
                bootstrapMajorVersion: 3,
                currentPage:"[[${typePage.pageNum == 0 ? 1 : typePage.pageNum}]]",
                totalPages:"[[${typePage.pages == 0 ? 1 : typePage.pages}]]",
                size:"normal",
                alignment:"center",
                pageUrl:function(type,page,current){
                    return "/type/findAll?pageNo="+page;
                }
            }
            $("#productTypePage").bootstrapPaginator(options);

            // 添加商品类型
            $(".addProductType").click(function(){
                $.ajax({
                    type:"post",
                    url:"/type/addType",
                    data:{"name":$("#productTypeName").val()},
                    dataType:"json",
                    success:function(result){
                        if(result.responseCode == "2001"){
                            location.href = "/type/findAll?pageNo=[[${typePage.pageNum == 0 ? 1 : typePage.pageNum}]]";
                        }else{
                            $("#errorMsg").tooltip({
                                title:"error",
                                placement:"center",
                                template:"<div class='tooltip errorMsg'>"+result.message+"</div>"
                            }).tooltip("show");
                        }
                    }
                })
            });

            // 修改设置默认值
            $(".doProTypeModify").click(function(){
                $.ajax({
                    type:"post",
                    url:"/type/findById",
                    data:{"id":$(this).attr("data-id")},
                    dataType:"json",
                    success:function(result){
                        if(result.responseCode == "2001"){
                            $("#proTypeNum").val(result.returnObject.id);
                            $("#proTypeName").val(result.returnObject.name);
                        }else{
                            $("#errorMsg").tooltip({
                                title:"error",
                                placement:"center",
                                template:"<div class='tooltip errorMsg'>"+result.message+"</div>"
                            }).tooltip("show");
                        }
                    }
                });
            });

            // 修改名称
            $(".updateProType").click(function(){
                $.ajax({
                    type:"post",
                    url:"/type/modifyName",
                    data:{
                        "id":$("#proTypeNum").val(),
                        "name":$("#proTypeName").val()
                    },
                    dataType:"json",
                    success:function(result){
                        if(result.responseCode == "2001"){
                            location.href = "/type/findAll?pageNo=[[${typePage.pageNum == 0 ? 1 : typePage.pageNum}]]";
                        }else{
                            $("#errorMsg").tooltip({
                                title:"error",
                                placement:"center",
                                template:"<div class='tooltip errorMsg'>"+result.message+"</div>"
                            }).tooltip("show");
                        }
                    }
                });
            });

            // 启用与禁用
            $("input[name='modifyStatus']").click(function(){
                $.ajax({
                    type:"post",
                    url:"/type/modifyStatus",
                    data:{"id":$(this).attr("data-id")},
                    dataType:"json",
                    success:function(result){
                        if(result.responseCode == "2001"){
                            location.href = "/type/findAll?pageNo=[[${typePage.pageNum == 0 ? 1 : typePage.pageNum}]]";
                        }else{
                            $("#errorMsg").tooltip({
                                title:"error",
                                placement:"center",
                                template:"<div class='tooltip errorMsg'>"+result.message+"</div>"
                            }).tooltip("show");
                        }
                    }
                });
            });
        });
    </script>
</head>

<body>
<div class="panel panel-default" id="userSet">
    <div class="panel-heading">
        <h3 class="panel-title">商品类型管理&nbsp;&nbsp;&nbsp;<span id="errorMsg"></span></h3>
    </div>
    <div class="panel-body">
        <input type="button" value="添加商品类型" class="btn btn-primary" id="doAddProTpye">
        <div class="modal fade" tabindex="-1" id="ProductType">
            <!-- 窗口声明 -->
            <div class="modal-dialog modal-lg">
                <!-- 内容声明 -->
                <div class="modal-content">
                    <!-- 头部、主体、脚注 -->
                    <div class="modal-header">
                        <button class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title">添加商品类型信息</h4>
                    </div>
                    <div class="modal-body text-center">
                        <div class="row text-right">
                            <label for="productTypeName" class="col-sm-4 control-label">类型名称：</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" id="productTypeName">
                            </div>
                        </div>
                        <br>
                    </div>
                    <div class="modal-footer">
                        <button class="btn btn-primary addProductType">添加</button>
                        <button class="btn btn-primary cancel" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </div>
        </div>
        <br>
        <br>
        <div class="show-list">
            <table class="table table-bordered table-hover" style='text-align: center;'>
                <thead>
                <tr class="text-danger">
                    <th class="text-center">编号</th>
                    <th class="text-center">类型名称</th>
                    <th class="text-center">状态</th>
                    <th class="text-center">操作</th>
                </tr>
                </thead>
                <tbody id="tb">
                    <tr th:each="type:${typePage.list}">
                        <td>[[${type.id}]]</td>
                        <td>[[${type.name}]]</td>
                        <td>
                            <span th:if="${type.status == 1}">启用</span>
                            <span th:if="${type.status == 0}">禁用</span>
                        </td>
                        <td class="text-center">
                            <input type="button" class="btn btn-warning btn-sm doProTypeModify" th:data-id="${type.id}" value="修改">
                            <span th:if="${type.status == 1}">
                                <input type="button" class="btn btn-danger btn-sm doProTypeDisable" name="modifyStatus" th:data-id="${type.id}" value="禁用">
                            </span>
                            <span th:if="${type.status == 0}">
                                <input type="button" class="btn btn-success btn-sm doProDisable" name="modifyStatus" th:data-id="${type.id}" value="启用">
                            </span>
                        </td>
                    </tr>
                </tbody>
            </table>
            <ul id="productTypePage"></ul>
        </div>
        <div class="modal fade" tabindex="-1" id="myProductType">
            <!-- 窗口声明 -->
            <div class="modal-dialog modal-lg">
                <!-- 内容声明 -->
                <div class="modal-content">
                    <!-- 头部、主体、脚注 -->
                    <div class="modal-header">
                        <button class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title">商品修改</h4>
                    </div>
                    <div class="modal-body text-center">
                        <div class="row text-right">
                            <label for="proTypeNum" class="col-sm-4 control-label">编号：</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" id="proTypeNum" readonly>
                            </div>
                        </div>
                        <br>
                        <div class="row text-right">
                            <label for="proTypeName" class="col-sm-4 control-label">类型名称</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" id="proTypeName">
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button class="btn btn-warning updateProType">修改</button>
                        <button class="btn btn-primary cancel" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>

</html>